/**
 * 如果要对数据进行翻页，vue继承该js
 */
//
var pdlist_content = {//分页数据提示组件
	props:["pd","message"],
	template: '<div v-if="pd.list.length==0">{{message||\'未查询到相关数据\'}}</div>',
	/*template: '<div v-if="pd.totalResult==0">未查询到相关数据</div>',*/
}
var vueappPageConfig={
	  	data:{
	  		pageDomId:null,
	  		currentPage:null,
	  		showCount:null,
	  		pageUrl:null,
	  		paramObject:{},
	  		checked:false,
	  		checkboxModel:[],
	  		pd:{list:[]}
	  	},
	  	methods: {
		    listPage:function(pageDomId,pageUrl,currentPage,showCount,paramObject,callBack){
		    	var _paramObject={showCount:showCount||10,currentPage:currentPage||1};
			    _paramObject=$.extend(_paramObject,paramObject);
			    var _thisvue=this;
			    this.checked=false;
			    _thisvue.pageDomId=pageDomId;
			    _thisvue.currentPage=currentPage;
			    _thisvue.pageUrl=pageUrl;
			    _thisvue.showCount=showCount;
//			    _thisvue.paramObject=_paramObject;
			    if(paramObject){
			    	_thisvue.paramObject=$.extend(true,_thisvue.paramObject,_paramObject);
			    }
			    $.ajax({
			    	async:false,
					type: "post",
					url: pageUrl,
					dataType: "json",
					data: _thisvue.paramObject,
					success: function (json) {
						json.pd.totalPage = json.totalPage;
						json.pd.totalResult = json.totalResult;
						_thisvue.pd=json.pd;
						_thisvue.totalPage = json.totalPage;
						if(callBack){
							callBack(json);
						}
						//显示分页
					    laypage({
					      cont: pageDomId, //容器。值支持id名、原生dom对象，jquery对象。【如该容器为】：<div id="page1"></div>
					      pages: json.totalPage, //通过后台拿到的总页数
					      curr: json.currentPage || 1, //当前页
					      jump: function(obj, first){ //触发分页后的回调
					        if(!first){ //点击跳页触发函数自身，并传递当前页：obj.curr
					        	_paramObject=$.extend(_thisvue.paramObject,{currentPage:obj.curr||1});
					        	_thisvue.listPage(pageDomId, pageUrl, _paramObject.currentPage, showCount, _paramObject,callBack)
					        }
					      }
					    });
					},
					error: function () {
					}
				});
		    },
		    refreshListPage:function(paramObject){
		    	 var _thisvue=this;
		    	 _thisvue.listPage(_thisvue.pageDomId, _thisvue.pageUrl, 1, _thisvue.showCount,paramObject);
		    },
		    checkedAll: function() {
		        var _this = this;
		        console.log(_this.checkboxModel);
		        if (this.checked) {
		        	//实现全选
		          _this.checkboxModel = [];
		          this.pd.list.forEach(function(item) {
		            _this.checkboxModel.push(item.id);
		          });
		        }else{//实现反选
		          _this.checkboxModel = [];
		        }
		      }
	  	  },
	  	watch: {//深度 watcher
	  	  'checkboxModel': {
	  	    handler: function (val, oldVal) { 
	  	      if (this.checkboxModel.length === this.pd.list.length) {
	  	        this.checked=true;
	  	      }else{
	  	        this.checked=false;
	  	      }
	  	    },
	  	    deep: true
	  	  }
	  	},
	  	components: {
	  	    'pdlist-content': pdlist_content
	  	  }
	  }